home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Oberon⁄F™ 1.2 / Preinstalled version / Text / Docu / Setters (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-07-08  |  21.0 KB  |  418 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. Helvetica
  23. Helvetica
  24. Helvetica
  25. TextSetters
  26. DEFINITION TextSetters;
  27.     IMPORT Stores, Views, Properties, TextModels, TextRulers;
  28.     CONST
  29.         lineBreak = 0; wordJoin = 1; wordPart = 2; flexWidth = 3;
  30.         char = TextModels.char; lchar = TextModels.lchar; view = TextModels.view;
  31.         string = 3; lstring = 4;
  32.     TYPE
  33.         LONGCHAR = INTEGER;
  34.         Pref = RECORD (Properties.Preference)
  35.             opts: SET;
  36.             endW: LONGINT;
  37.             dsc: LONGINT
  38.         END;
  39.         Reader = POINTER TO ReaderDesc;
  40.         ReaderDesc = RECORD
  41.             r-: TextModels.Reader;
  42.             type-: SET;
  43.             string: ARRAY 64 OF CHAR;
  44.             lstring: ARRAY 64 OF LONGCHAR;
  45.             view: Views.View;
  46.             textOpts: SET;
  47.             mask: LONGCHAR;
  48.             setterOpts: SET;
  49.             w, endW, h, dsc: LONGINT;
  50.             attr: TextModels.Attributes;
  51.             eot: BOOLEAN;
  52.             pos: LONGINT;
  53.             x: LONGINT;
  54.             adjStart: LONGINT;
  55.             spaces: INTEGER;
  56.             vw: LONGINT;
  57.             hideMarks: BOOLEAN;
  58.             ruler: TextRulers.Ruler;
  59.             rpos: LONGINT;
  60.             PROCEDURE (rd: Reader) Set (old: TextModels.Reader;
  61.                                                             text: TextModels.Model; x, pos: LONGINT;
  62.                                                             ruler: TextRulers.Ruler; rpos, vw: LONGINT; hideMarks: BOOLEAN);
  63.             PROCEDURE (rd: Reader) Read;
  64.             PROCEDURE (rd: Reader) AdjustWidth (start, pos: LONGINT;
  65.                                                                             VAR box: LineBox; VAR w: LONGINT);
  66.             PROCEDURE (rd: Reader) SplitWidth (w: LONGINT): LONGINT
  67.         END;
  68.         Setter = POINTER TO SetterDesc;
  69.         SetterDesc = RECORD (Stores.StoreDesc)
  70.             text-: TextModels.Model;
  71.             defRuler-: TextRulers.Ruler;
  72.             hideMarks-: BOOLEAN;
  73.             PROCEDURE (s: Setter) CopyFrom (source: Setter);
  74.             PROCEDURE (s: Setter) ConnectTo (text: TextModels.Model; defRuler: TextRulers.Ruler;
  75.                                                                         vw: LONGINT; hideMarks: BOOLEAN);
  76.             PROCEDURE (s: Setter) ThisPage (pageH: LONGINT; pageNo: INTEGER): LONGINT;
  77.             PROCEDURE (s: Setter) NextPage (pageH: LONGINT; start: LONGINT): LONGINT;
  78.             PROCEDURE (s: Setter) ThisSequence (pos: LONGINT): LONGINT;
  79.             PROCEDURE (s: Setter) NextSequence (start: LONGINT): LONGINT;
  80.             PROCEDURE (s: Setter) PreviousSequence (start: LONGINT): LONGINT;
  81.             PROCEDURE (s: Setter) GetWord (pos: LONGINT; VAR beg, end: LONGINT);
  82.             PROCEDURE (s: Setter) GetLine (start: LONGINT; VAR box: LineBox);
  83.             PROCEDURE (s: Setter) GetBox (start, end, maxW, maxH: LONGINT; VAR w, h: LONGINT);
  84.             PROCEDURE (s: Setter) NewReader (old: Reader): Reader;
  85.             PROCEDURE (s: Setter) GridOffset (dsc: LONGINT; VAR box: LineBox): LONGINT
  86.         END;
  87.         LineBox = RECORD
  88.             len: LONGINT;
  89.             ruler: TextRulers.Ruler;
  90.             rpos: LONGINT;
  91.             left, right, asc, dsc: LONGINT;
  92.             rbox, bop, adj, eot, views: BOOLEAN;
  93.             skipOff: LONGINT;
  94.             adjOff: LONGINT;
  95.             spaces: INTEGER;
  96.             adjW: LONGINT
  97.         END;
  98.         Directory = POINTER TO DirectoryDesc;
  99.         DirectoryDesc = RECORD
  100.             PROCEDURE (d: Directory) New (): Setter
  101.         END;
  102.     VAR dir-, stdDir-: Directory;
  103.     PROCEDURE SetDir (d: Directory);
  104. END TextSetters.
  105. TextSetters set texts (one-dimensional streams of characters and embedded views) into two
  106. dimensional columns or pages. Special text
  107. aware views embedded in the set text, so-called rulers, are interpreted as requests for special setting formats.
  108. Warning: The interface of TextSetters and its role in the text subsystem may change in future releases of Oberon/F. (TextSetters is included in this documentation for its fundamental role in the task performed by TextViews.)
  109. CONST lineBreak, wordJoin, wordPart, flexWidth
  110. Possible values of Pref.opts indicating preferences of setter
  111. aware views embedded in a text. The inclusion of lineBreak overrides any possible inclusion of wordJoin.
  112. If lineBreak is included, the setter is requested to break the line just after the view.
  113. If wordJoin is included, the view requests that it should not be used as a position to break the words to the left and to the right of the view at the end of a line.
  114. If wordPart is included, the view is treated as part of the word that it is embedded into (which effects the range selected by a "select word" operation).
  115. If flexWidth is included, the view is treated the same way as ordinary blanks, i.e. its width is adjusted when setting a line in fully adjusted mode.
  116. CONST char, lchar, view, string, lstring
  117. Possible elements of Reader.type, indicating which of the reader fields are valid. {char, lchar, view} correspond to the constants of same name defined in TextModels.
  118. TYPE LONGCHAR
  119. Type of long characters.
  120. TYPE Pref
  121. Possible preferences of setter
  122. aware views embedded into a text.
  123. opts: SET
  124. Setting options drawn from {lineBreak, wordJoin, wordPart, flexWidth}, as defined above.
  125. endW: LONGINT    preset to width of view
  126. If view happens to be placed at the end of a line, i.e. a line break is immediately following, the view may request a width different from its usual width. (For example, a soft
  127. hyphen has a positive end width, while it has a zero width; a blank has a positive width, but a zero end width.)
  128. dsc: LONGINT    preset to dominating line descender
  129. A view may request a special descender value, thereby adjusting its placement relative to the baseline.
  130. TYPE Reader
  131. Interface
  132. A reader to read through lines returned by a setter. The reader is a conceptual extension of a TextModels.Reader, but instead of just returning the elements of a stream, it also sets the elements on a line and returns placement coordinates relative to the lines baseline origin.
  133. r-: TextModels.Reader
  134. The text reader used to connect the reader to a text. The text reader state is used as a one element look
  135. ahead state for the reader.
  136. type-: SET
  137. The type of possible interpretations of the element last read, drawn from {char, lchar, view, string, lstring}. The validity of the fields string, lstring, and view depends on this field.
  138. string: ARRAY 64 OF CHAR
  139. The element read most recently was a character (char IN type) or string of characters (string IN type). Single characters are returned in string[0]. In case of char IN type and view IN type, the element read most recently was a view masked as a character.
  140. lstring: ARRAY 64 OF LONGCHAR
  141. The element read most recently was a long character (lchar IN type) or string of long characters (lstring IN type). Single long characters are returned in lstring[0]. In case of lchar IN type and view IN type, the element read most recently was a view masked as a long character.
  142. view: Views.View;
  143. The element read most recentlyd was an embedded view.
  144. textOpts: SET
  145. mask: LONGCHAR
  146. setterOpts: SET
  147. w, endW, h, dsc: LONGINT
  148. attr: TextModels.Attributes
  149. Properties of the element read most recently: Its text options (if text
  150. aware, else preset default); its mask character (if TextModels.maskChar IN textOpts); its setter options (if setter
  151. aware, else preset default); its width, end width (if setter
  152. aware, else preset default), height, and descender (if setter
  153. aware, else preset default); its text attributes.
  154. eot: BOOLEAN
  155. Set if the last trial to read hit the end of text.
  156. pos: LONGINT
  157. Position of the reader in the text (one past the element read most recently).
  158. x: LONGINT
  159. Horizontal position of the reader in the line. To be advanced by client of reader. For non
  160. adjusted setting, increment by w, else utilize AdjustWidth below.
  161. adjStart: LONGINT
  162. The first position (inclusive) to begin space adjustment at. This is used to suppress space adjustment in all but the last section of several tab-separated sections of a line.
  163. spaces: INTEGER
  164. Number of spaces encountered by reader so far. (Reset to 0 when adjStart gets reset on reading a tab.)
  165. vw: LONGINT
  166. Width to set text against.
  167. hideMarks: BOOLEAN
  168. Hideable marks are requested to be hidden in the currect line. If the reader encounters an embedded view that by its text preferences is hideable and hideMarks is set, then the view is reduced to zero width and height.
  169. ruler: TextRulers.Ruler
  170. Ruler dominating the setting of the current line.
  171. rpos: LONGINT
  172. Position of the dominating ruler in the text. (rpos = -1 if the ruler is not part of the text and there is no ruler in the text that dominates the current line. Typically, this is used to apply a default ruler to the beginning of a text that has no ruler at position 0.)
  173. PROCEDURE (rd: Reader) Set (old: TextModels.Reader;
  174.                                                         text: TextModels.Model; x, pos: LONGINT;
  175.                                                         ruler: TextRulers.Ruler; rpos, vw: LONGINT;
  176.                                                         hideMarks: BOOLEAN)
  177. Default
  178. Connect the reader to a text line, possibly re
  179. using an old text reader that is no longer in use. The reader is given the text, the line's horizontal left margin x, the line's starting position pos , the ruler and its position rpos dominating the line, and whether hideable marks are to be hidden. vw is the width against which text should be set.
  180. text # NIL    20
  181. 0 <= pos    21
  182. pos <= text.Length()    22
  183. ruler # NIL    23
  184. -1 <= rpos    24
  185. rpos <= pos    25
  186. rd.r # NIL
  187. rd.r.Base() = text
  188. rd.r.eot OR rd.r.Pos() = pos + 1
  189. rd.type = {}
  190. rd.string[0] = 0X
  191. rd.lstring[0] = 0
  192. rd.view = NIL
  193. rd.textOpts = {}
  194. rd.setterOpts = {}
  195. rd.w = 0, rd.endW = 0, rd.h = 0, rd.dsc = 0
  196. rd.attr = NIL
  197. rd.eot = FALSE
  198. rd.pos = pos
  199. rd.x = x
  200. rd.adjStart = pos, rd.spaces = 0
  201. rd.ruler = ruler, rd.rpos = rpos
  202. rd.hideMarks = hideMarks
  203. PROCEDURE (rd: Reader) Read
  204. Base (to be called by extensions first)
  205. Read next element in line.
  206. ~rd.r.eot
  207.     rd.r.Pos() = rd.r'.Pos() + 1
  208. ~rd.eot
  209.     rd.type * {char, lchar, view} # 0
  210.         rd.pos = rd'.pos + 1
  211.     string IN rd.type
  212.         rd.pos = rd'.pos + Length(rd.string)
  213.     lstring IN rd.type
  214.         rd.pos = rd'.pos + Length(rd.lstring)
  215. rd.eot
  216.     rd.w = rd.endW = 0
  217.     rd.h = ruler.style.attr.asc + ruler.style.attr.dsc
  218.     rd.dsc = ruler.style.attr.dsc
  219. PROCEDURE (rd: Reader) AdjustWidth (start, pos: LONGINT;
  220.                                                                         VAR box: LineBox; VAR w: LONGINT)
  221. Interface
  222. Given a line box, its starting position start, and a position pos, AdjustWidth takes an element's width w and adjusts it according to the formatting requirements of the line.
  223. PROCEDURE (rd: Reader) SplitWidth (w: LONGINT): LONGINT
  224. Interface
  225. For the element read last by the reader, compute a split width. This is used for interactive purposes, where the split width splits coordinates into two half intervals: All coordinates left of the split point belong to the left edge of the element, all coordinates right of the split point belong to the right edge.
  226. 0 <= result <= w
  227. TYPE Setter
  228. Interface, Extension
  229. A setter can be used to set a text into lines, paragraphs, columns, and pages.
  230. text-: TextModels.Model    setter connected iff text # NIL
  231. Text to be set.
  232. defRuler-: TextRulers.Ruler
  233. Default ruler to be used to set the beginning of the text, in case the text has no ruler at position 0.
  234. hideMarks-: BOOLEAN
  235. If set, all embedded views that are by their preference hideable, will be reduced to zero width and zero height.
  236. PROCEDURE (s: Setter) CopyFrom (source: Setter)
  237. Copy a non
  238. initialized setter from an initialized source setter.
  239. source # NIL    (not explicitly checked)
  240. PROCEDURE (s: Setter) ConnectTo (text: TextModels.Model; defRuler: TextRulers.Ruler;
  241.                                                                 vw: LONGINT; hideMarks: BOOLEAN)
  242. Disconnect setter from the text it was previously connected to (if any), and connect setter to given text (if any) using default ruler defRuler and hiding marks if requested by hideMarks. vw is the width against which text should be set.
  243. text # NIL    20
  244. defRuler # NIL    21
  245. text = NIL
  246.     s.text = NIL
  247.     s.defRuler = NIL
  248. text # NIL
  249.     s.text = text
  250.     s.defRuler = defRuler
  251.     s.hideMarks = hideMarks
  252. PROCEDURE (s: Setter) ThisPage (pageH: LONGINT; pageNo: INTEGER): LONGINT
  253. Interface
  254. For a page of height pageH, determine the starting position for page number pageNo (with page numbering starting from 0).
  255. Connected(s)    20
  256. 0 <= pageNo    21
  257. pageNo > LastPageNo(s.text, pageH)
  258.     result = -1
  259. pageNo <= LastPageNo(s.text, pageH)
  260.     result = PageStart(pageNo)
  261. PROCEDURE (s: Setter) NextPage (pageH: LONGINT; start: LONGINT): LONGINT
  262. Interface
  263. For a page of height pageH and a current page's starting position start, determine the starting position of the next page.
  264. Connected(s)    20
  265. 0 <= start    21
  266. start <= s.text.Length()    22
  267. Exists pNo: s.ThisPage(pageH, pNo) = start    23
  268. start = LastPage(s.text, pageH)
  269.     result = start
  270. start < LastPage(s.text, pageH)
  271.     result = PageStart(PageNo(s.text, start) + 1)
  272. PROCEDURE (s: Setter) ThisSequence (pos: LONGINT): LONGINT
  273. Interface
  274. Locate the starting position of the (line or para separated) sequence containing position pos.
  275. Connected(s)    20
  276. 0 <= pos    21
  277. pos <= s.text.Length()    22
  278. result = 0  OR  char[result - 1] IN {line, para}
  279. PROCEDURE (s: Setter) NextSequence (start: LONGINT): LONGINT
  280. Interface
  281. Locate the starting position of the next (line or para separated) sequence, given a starting position start of a current sequence.
  282. Connected(s)    20
  283. 0 <= start    21
  284. start <= s.text.Length()    22
  285. s.ThisSequence(start) = start    23
  286. All pos: start < pos < s.text.Length(): s.ThisSequence(pos) = start
  287.     result = start
  288. s.ThisSequence(result - 1) = start
  289.     result > start
  290.     s.ThisSequence(result) = result
  291. PROCEDURE (s: Setter) PreviousSequence (start: LONGINT): LONGINT
  292. Locate the starting position of the previous (line or para separated) sequence, given a starting position start of a current sequence.
  293. Connected(s)    20
  294. 0 <= start    21
  295. start <= s.text.Length()    22
  296. s.ThisSequence(start) = start    23
  297. start = 0
  298.     result = 0
  299. start > 0
  300.     result = s.ThisSequence(start - 1)
  301. PROCEDURE (s: Setter) ThisLine (pos: LONGINT): LONGINT
  302. Locate the starting position of the line containing pos.
  303. Connected(s)    20
  304. 0 <= pos    21
  305. pos <= s.text.Length()    22
  306. result <= pos
  307. pos < s.NextLine(result)  OR  LastLine(result)
  308. PROCEDURE (s: Setter) NextLine (start: LONGINT): LONGINT
  309. Interface
  310. Locate the starting position of the next line, given the starting position start of the current line.
  311. Connected(s)    20
  312. 0 <= start    21
  313. start <= s.text.Length()    22
  314. s.ThisLine(start) = start    23
  315. LastLine(start)
  316.     result = start
  317. ~LastLine(start)
  318.     result > start
  319.     s.ThisLine(result - 1) = start
  320. PROCEDURE (s: Setter) PreviousLine (start: LONGINT): LONGINT
  321. Interface
  322. Locate the starting position of the previous line, given the starting position start of the current line.
  323. Connected(s)    20
  324. 0 <= start    21
  325. start <= s.text.Length()    22
  326. s.ThisLine(start) = start    23
  327. start = 0
  328.     result = 0
  329. start > 0
  330.     result < start
  331.     result = s.ThisLine(start - 1)
  332. PROCEDURE (s: Setter) GetWord (pos: LONGINT; VAR beg, end: LONGINT)
  333. Locate the beginning and ending positions of the word containing position pos. A word is a sequence of characters with code > " ", or views with mask > " ", or views with preference wordPart.
  334. Connected(s)    20
  335. 0 <= pos    21
  336. pos <= s.text.Length()    22
  337. beg <= pos <= end
  338. PROCEDURE (s: Setter) GetLine (start: LONGINT; VAR box: LineBox)
  339. Interface
  340. Compute the characteristic box of the line with starting position start. (Cf. type LineBox below.)
  341. Connected(s)    20
  342. 0 <= start    21
  343. start <= s.text.Length()    22
  344. s.ThisLine(start) = start    23
  345. min{box.left, box.first} <= box.left <= box.right <= ruler.right
  346. ~box.eot
  347.     box.ruler # NIL
  348.     box.len > 0
  349. PROCEDURE (s: Setter) GetBox (start, end, maxW, maxH: LONGINT; VAR w, h: LONGINT)
  350. Interface
  351. Get the bounding box of a text stretch beginning at a line starting position start and ending at position end. The box computation will terminate if either the text stretch has been fully set, or if the box reached either of the limits, maxW bounding the box width, or maxH bounding the box height.
  352. Connected(s)    20
  353. 0 <= start    21
  354. start <= end    22
  355. end <= s.text.Length()    23
  356. maxW > Views.undefined
  357.     w <= maxW
  358. maxH > Views.undefined
  359.     h <= maxH
  360. PROCEDURE (s: Setter) NewReader (old: Reader): Reader
  361. Return a new reader, possibly reusing a given old reader that is no longer in use. (Whether the old reader is actually reused depends on internal compatibility conditions.)
  362. Connected(s)    20
  363. result # NIL
  364. PROCEDURE (s: Setter) GridOffset (dsc: LONGINT; VAR box: LineBox): LONGINT
  365. Given the descender dsc of the preceding line and the current line characteristics box, return the grid correction to force the current line to the line grid. If the current line is the first line (of the text or on the current page), dsc = -1 should be passed.
  366. Connected(s)
  367. dsc >= -1
  368. ~box.rbox
  369.     Exists k: k >= 0: dsc + GridOffset(dsc, box) + box.asc =
  370.                                     k * ruler.grid >= ruler.asc + ruler.grid
  371. box.rbox
  372.     result = 0
  373. TYPE LineBox
  374. The characteristics of a line set by a setter.
  375. len: LONGINT
  376. Length of the line.
  377. ruler: TextRulers.Ruler
  378. rpos: LONGINT
  379. Ruler dominating the line, and its position in the text. (rpos = -1 indicates that the line is dominated by the default ruler.)
  380. left, right, asc, dsc: LONGINT
  381. Left and right margins, and ascender and descender of the line's bounding box.
  382. rbox: BOOLEAN
  383. The line solely contains a ruler or a paragraph separator (para character or mask).
  384. bop: BOOLEAN
  385. The line is the first of a paragraph: Its left margin is ruler.first.; otherwise the left margin is ruler.left.
  386. adj: BOOLEAN
  387. The line needs adjustment when finally rendered: At least one element of the line needs to be artificially changed in width to achieve the requested formatting effect.
  388. eot: BOOLEAN
  389. The line is either empty, or it contains the last element of the text which is neither a line nor a para character or mask.
  390. views: BOOLEAN
  391. The line contains at least one embedded view.
  392. skipOff: LONGINT    0 <= skipOff <= len
  393. The characters in [skipOff, len) take on width endW.
  394. adjOff: LONGINT    0 <= adjOff <= len
  395. Offset of last block (sequence with no tab enclosed) in box. If the line is adjusted (centered, right flush, or fully adjusted), then this is the offset into the line where adjustment begins.
  396. spaces: INTEGER    valid and > 0 if adj
  397. Number of spaces subject to adjustment.
  398. adjW: LONGINT    valid and > 0 if adj
  399. The adjustment delta to be added either to the front of the last block for centered or right flushed formats, or to each space element (blank or view mapped to blank or view with preference flexWidth) for fully adjusted formats.
  400. TYPE Directory
  401. Interface
  402. Directory for setters.
  403. PROCEDURE (d: Directory) New (): Setter
  404. Interface
  405. Return a new setter.
  406. VAR dir-, stdDir-: Directory    dir # NIL, stdDir # NIL, stable stdDir = d
  407. Directory and standard directory objects.
  408. PROCEDURE SetDir (d: Directory)
  409. Set the directory object.
  410. d # NIL    20
  411. dir = d
  412. TextControllers.StdCtrlDesc
  413. TextControllers.ControllerDesc
  414. Containers.ControllerDesc
  415. Controllers.ControllerDesc
  416. Helvetica
  417. Documents.ControllerDesc
  418.